<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');


$browser = new sfTestFunctional(new sfBrowser());	

/*$users = Doctrine::getTable('User')->createQuery('a')->execute();
foreach ($users as $user): 
  $loginId=$user->getLoginid();
  $browser->info('1 - The user page')->
    get('/user/index/')-> 
    info('  1.'.$loginId.' - user id for user: '.$user->getName().' on the homepage is clickable with same loginId as being displayed')->
    click($loginId, array(), array('position' => 1))->
    with('request')->begin()->
      isParameter('module', 'user')->
      isParameter('action', 'show')->
      isParameter('loginid', $loginId)->  
  end();
endforeach;
*/
$usersToInsert = 5;
for ($i=1; $i<=$usersToInsert; $i++)
{
  $browser->info('2 - User Management')->
  info('  2.'.$i.' - Create a new User | Success Scenario')->
 
  get('/user/new/')->
  with('request')->begin()->
    isParameter('module', 'user')->
    isParameter('action', 'new')->
  end()-> 
  click('Save', array('user' => array(
  
      'emailaddress' => 'test'.$i.'@example.com',
      'name'         => 'Test User'.$i,
      'userrole'       => '3',
      
  )))->
 
  with('request')->begin()->
    isParameter('module', 'user')->
    isParameter('action', 'create')->
  end()->
  with('form')->begin()->
	hasErrors(false)->
	end();
  $browser->setTester('doctrine', 'sfTesterDoctrine');
  $browser->with('doctrine')->begin()->
    check('User', array(
    'status'     => '1',
    'loginname' => 'test'.$i.'@example.com',
    'password'    => base64_encode('Test User'.$i),
    ))->
  end();
	/*->
  with('form')->debug();
  */
}
$usersToInsert = 5;
for ($i=1; $i<=$usersToInsert; $i++)
{
  $browser->info('2 - User Management')->
  info('  2.'.$i.' - Create a new User | invalid values')->
 
  get('/user/new/')->
  with('request')->begin()->
    isParameter('module', 'user')->
    isParameter('action', 'new')->
  end()-> 
  click('Save', array('user' => array(
  
      'emailaddress' => 'test'.$i.'@',
      'name'         => 'Test User'.$i,
      'userrole'       => '3',
      
  )))->
 
  with('request')->begin()->
    isParameter('module', 'user')->
    isParameter('action', 'create')->
  end()->
  with('form')->begin()->
	hasErrors(1)->
	isError('userrole', 'required')->
	isError('name', 'required')->
	isError('emailaddress', 'invalid')->
	end();
 
	/*->
  with('form')->debug();
  */
}

/*
$browser->info('2 - User Management')->
  info('  2.1 - Create a new User | Fail Scenario (invalid email format)')->
 
  get('/user/new/')->
  with('request')->begin()->
    isParameter('module', 'user')->
    isParameter('action', 'new')->
  end()-> 
  click('Save', array('user' => array(
  
      'emailaddress' => 'test.com',
      'name'         => 'Test User',
      'roleid'       => '3',
      
  )))->
 
  with('request')->begin()->
    isParameter('module', 'user')->
    isParameter('action', 'create')->
  end()
;
//$browser->with('response')->debug();
*/